package com.company.day2;
import java.util.Scanner;
//(几何:两个矩形）输人两个矩形中点的x坐标和y坐标以及它们的宽度和高度，然后判定第二个矩形是在第一个矩形内，还是和第一个矩形重叠，
public class RectangleRelation {
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            System.out.printf("Enter the center points and width and height of two rectangles: ");
            double x1 = input.nextDouble();
            double y1 = input.nextDouble();
            double w1 = input.nextDouble();
            double h1 = input.nextDouble();
            double x2 = input.nextDouble();
            double y2 = input.nextDouble();
            double w2 = input.nextDouble();
            double h2 = input.nextDouble();
            if(Math.abs(x1-x2) <= w1-w2 && Math.abs(y1-y2) <= h1-h2){
                System.out.printf(" The second rectangle is inside the first rectangle. ");
            }else if(Math.abs(x1-x2) > (w1-w2)/2 && Math.abs(x1-x2) < (w1+w2)/2
                    && Math.abs(y1-y2) > (h1-h2)/2 && Math.abs(y1-y2) < (h1+h2)/2) {
                System.out.printf(" The second rectangle overlaps the first rectangle. ");
            }else{
                System.out.printf(" Neither ! ");
            }
        }
}
